﻿using System;

namespace ExtendedMvc.Elements {
	/// <summary>
	/// Column for the grid
	/// </summary>
	public abstract class GridColumnBase<TColumn, TModel> : IGridColumnBase<TModel>
		where TColumn : IGridColumnBase<TModel>
		where TModel : class {
		private readonly string _name;
		private Func<TModel, bool> _showIf = x => true;
		private string _headerText;

		protected Func<TModel, bool> showIf { get { return _showIf; } }

		public GridColumnBase(string name) {
			_name = name;
		}

		public virtual string Name { get { return _name; } }

		public IGridColumnBase<TModel> Header(string value) {
			_headerText = value;
			return (IGridColumnBase<TModel>)this;
		}

		public IGridColumnBase<TModel> ShowIf(Func<TModel, bool> func) {
			_showIf = func;
			return (IGridColumnBase<TModel>)this;
		}

		//public IGridColumn<T> DoNotEncode() {
		//    _htmlEncode = false;
		//    return this;
		//}

		public virtual object GetHeader() { return _headerText; }

		public abstract object GetData(TModel source);

		public virtual object GetFooter() { return string.Empty; }
	}
}
